<template>
	<div>
		<u-popup v-model="show" mode="bottom" border-radius="30" :safe-area-inset-bottom="true">
      <div class="top flex">
        <u-icon class="icon" name="arrow-down" size="32" @click="cancel"></u-icon>
        <span class="confirm" @click="confirm">确定</span>
      </div>
      <div class="sorts flex" v-if="type=='subject'">
        <div class="sort" :class="value==item.value && 'on'" v-for="(item, index) in list" :key="index" @click="change(item.value)">{{ item.title }}</div>
      </div>
      <div class="sorts" v-else-if="type=='warn'">
        <div class="tip">您确定删除选定的信息吗？</div>
        <u-checkbox v-model="filter_similar">类似信息不预警</u-checkbox>
      </div>
			<div class="btn" @click="cancel">取消</div>
		</u-popup>
		<u-toast ref="uToast" />
	</div>
</template>

<script>
import { articleDel } from "@/api/subject.js";
import { delWarn } from "@/api/warn.js";

export default {
  props: {
    type: {
      type: String,
      default: ""
    },
  },
  data() {
    return {
      list: [
        {
          title: "仅删除本条信息",
          value: 1
        },
        {
          title: "删除全部相似信息",
          value: 2
        },
        {
          title: "删除本专题相似信息",
          value: 3
        },
      ],
      value: 1,
      filter_similar: false
    }
  },
  computed: {
    show: {
      get() {
        return this.$store.state.isDel;
      },
      set(value) {
        this.$store.state.isDel = value;
      }
    },
  },
  methods: {
    change(val) {
      this.value = val;
    },
    cancel() {
      this.$store.state.isDel = false;
    },
    confirm() {
      let ids = this.$store.state.selectedArticle.map(item=>item.id);
      if(this.type == "subject"){
        articleDel({
          type: this.value,
          is_batch: "t",
          ids: ids
        }).then(({code})=>{
          if(code == 200){
            this.$refs.uToast.show({
              title: "删除成功",
              type: "success",
              callback: ()=>{
                this.$parent.isAllCheck = false;
                this.$store.state.multipleMode = false;
                this.cancel();
								uni.showTabBar();
                this.$store.commit("isRefreshAllListHandle", new Date().getTime());
              }
            });
          }
        });
      }else if(this.type == "warn"){
        delWarn({
          ids: ids,
          filter_similar: this.filter_similar?"t":"f"
        }).then(({code})=>{
          if(code == 200){
            this.$refs.uToast.show({
              title: "删除成功",
              type: "success",
              callback: ()=>{
                this.$parent.isAllCheck = false;
                this.$store.state.multipleMode = false;
                this.cancel();
								uni.showTabBar();
                this.$store.commit("isRefreshWarnListHandle", new Date().getTime());
              }
            });
          }
        });
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.top{
  font-size: 36rpx;
  font-weight: bold;
  padding: 20rpx;
  border-bottom: 1rpx solid #ccc;
  justify-content: space-between;
  align-items: center;
  .icon{
    cursor: pointer;
  }
  .confirm{
    cursor: pointer;
    font-size: 32rpx;
    color: #1E62FC;
  }
}
.sorts{
  padding: 20rpx;
  box-sizing: border-box;
  flex-wrap: wrap;
  justify-content: space-between;
  .sort{
    cursor: pointer;
    box-sizing: border-box;
    width: 48%;
    padding: 16rpx 0;
    text-align: center;
    border: 1rpx solid #F0F0F0;
    border-radius: 8rpx;
    margin-bottom: 2%;
    color: #333;
  }
  .on{
    color: #fff;
    background-color: #1E62FC;
    border: 1rpx solid #1E62FC;
  }
  .tip{
    font-size: 32rpx;
    padding: 20rpx 0;
  }
}
.btn{
	border-top: 2rpx solid #eee;
	height: 88rpx;
	line-height: 88rpx;
	text-align: center;
	cursor: pointer;
	font-size: 32rpx;
	
	&:active{
		opacity: 0.9;
	}
}
</style>